package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);unique;not null;comment:用户名"`
	Password string `gorm:"type:char(32);not null;comment:密码"`
	Salt     string `gorm:"type:varchar(5);not null;comment:盐"`
	Mobile   string `gorm:"type:char(11);unique;comment:手机号"`
}
type RealName struct {
	gorm.Model
	UserId   uint   `gorm:"unique;not null;comment:用户ID"`
	RealName string `gorm:"type:varchar(20);unique;not null;comment:姓名"`
	IdCard   string `gorm:"type:varchar(20);unique;not null;comment:身份证号"`
}

// 手机号查询信息
func (u *User) FindByMobile(mobile string) error {
	return db.Where("mobile = ?", mobile).Find(&u).Error
}

// 创建实名信息
func (u *RealName) Create() error {
	return db.Create(&u).Error
}

func (u *RealName) GetUserRealNameByUserIdOrIdCard(userId string, idCard string) error {
	return db.Where("user_id = ?", userId).Or("id_card", idCard).First(&u).Error
}
